import { ClipboardGetText, ClipboardSetText } from "@runtime";
import { Button, message } from "antd";
import { useEffect } from "react";
import { StartClipboard, StopClipboard } from "@go/app/ClipboardApp";
import { RegisterHotkey, UnregisterHotkey } from "@go/app/HotkeyApp";

const Index = () => {
  // useEffect(() => {
  //   // 监听剪切板变化
  //   const listener = (e: any) => {
  //     console.log(e.clipboardData.getData("text"));
  //   };
  //   document.addEventListener("copy", listener);
  //   return () => {
  //     document.removeEventListener("paste", listener);
  //   };
  // }, []);
  return (
    <div>
      <h1>首页</h1>
      <h1>----------功能测试----------</h1>
      <Button
        disabled
        type="primary"
        onClick={async () => {
          const res = await ClipboardGetText();
          message.info(res);
        }}
      >
        获取剪切板
      </Button>
      <Button
        disabled
        type="primary"
        onClick={async () => {
          const res = await ClipboardSetText("这是测试文本");
          message.info(res);
        }}
      >
        剪贴板设置文本
      </Button>
      <h1>----------功能测试----------</h1>
      <Button disabled type="primary" onClick={StartClipboard}>
        开启剪切板监控
      </Button>
      <Button disabled type="primary" onClick={StopClipboard}>
        关闭剪切板监控
      </Button>
      <h1>----------功能测试----------</h1>
      <Button
        disabled
        type="primary"
        onClick={() => {
          RegisterHotkey("p", 111);
        }}
      >
        快捷键测试1
      </Button>
      <Button
        disabled
        type="primary"
        onClick={() => {
          UnregisterHotkey(111);
        }}
      >
        移除快捷键1
      </Button>
      <Button
        disabled
        type="primary"
        onClick={() => {
          RegisterHotkey("s_l", 222);
        }}
      >
        快捷键测试2
      </Button>
      <Button
        disabled
        type="primary"
        onClick={() => {
          UnregisterHotkey(222);
        }}
      >
        移除快捷键1
      </Button>
    </div>
  );
};

export default Index;
